import sys
import time
import random


# 优惠券
coupons = [
    ["电视机",0.8],
    ["洗衣机",0.8],
    ["冰箱",0.8],
    ["空调",0.8],
    ["Mac 电脑",0.8],
    ["联想thinkPad e580",0.8],
    ["华为 m240青春版",0.8],
    ["榴莲",0.8],
    ["驴肉火烧",0.8],
    ["辣条",0.8],
    ["可乐",0.8],
    ["福临门大米",0.8]
]

# 空的购物车
mycart = []

# 足够的钱
money = input("请输入您的银行卡余额：")
if money.isdigit():
    money = int(money)  # 强制转化
else:
    print("请输入正确的银行卡余额！")
    sys.exit()

# 商品
shop = [
    ["电视机",2500],
    ["洗衣机",1200],
    ["冰箱",1000],
    ["空调",2400],
    ["Mac 电脑",12000],
    ["联想thinkPad e580",4500],
    ["华为 m240青春版",1100],
    ["榴莲",100],
    ["驴肉火烧",10.5],
    ["辣条",5],
    ["可乐",3],
    ["福临门大米",40.5]
]

print("-----------------欢迎来到Jason商城-----------------------")
result = input("你想抽一张优惠券吗？（yes/no）：")
coupon = -1
if result == 'yes':
    if result == 'yes':
        coupon = random.randint(0, 11)
    print("恭喜您抽到了", coupons[coupon][0], coupons[coupon][1]*10,"折优惠券，在本次购物过程中，您购买", coupons[coupon][0], "时都可以享受", coupons[coupon][1]*10,"折优惠！")

# 是否购物的标志
buy_flag = 0

while True:
    for index,item in enumerate(shop): # index = 0 ,  item = [电视机，1000]
        print(index,item)

    num = input("请输入你想要的商品编号：") # num =  6

    if num == "q" or num == "Q":
        if len(mycart) == 0:
            print("您还没有购买商品，不能打印购物小条！欢迎下次光临！")
        else:
            print("欢迎下次光临！ ByeBye您嘞！")
            buy_flag = 1
        break # 退出循环
    elif num.isdigit():  # "56" --> 56   "a" --->
        num = int(num)
        # 购物
        if num >= len(shop):
            print("对不起，没有这个商品！别瞎弄！")
        else:
            if num == coupon:
                print("您正在使用优惠券！")
                if money >= shop[num][1] * coupons[coupon][1]:
                    flag = 0
                    for i in mycart:
                        if i[0] == shop[num][0]:
                            i[1] = i[1] + 1
                            i[2] = i[2] + shop[num][1] * coupons[coupon][1]
                            money = money - shop[num][1] * coupons[coupon][1]
                            flag = 1
                            break
                    if flag == 0:
                        commodity = [shop[num][0], 1, shop[num][1] * coupons[coupon][1]]
                        money = money - shop[num][1] * coupons[coupon][1]
                        mycart.append(commodity)
                    print("恭喜，购买成功！您的余额还剩:￥",money)
                else:
                    print("穷鬼，钱不足！请到其他地方购买！")
            else:
                if money >= shop[num][1]:
                    flag = 0
                    for i in mycart:
                        if i[0] == shop[num][0]:
                            i[1] = i[1] + 1
                            i[2] = i[2] + shop[num][1]
                            money = money - shop[num][1]
                            flag = 1
                            break
                    if flag == 0:
                        commodity = [shop[num][0], 1, shop[num][1]]
                        money = money - shop[num][1]
                        mycart.append(commodity)
                    print("恭喜，购买成功！您的余额还剩:￥",money)
                else:
                    print("穷鬼，钱不足！请到其他地方购买！")
    else:
        print("对不起，输入错误，别瞎弄！请重新输入！")

if buy_flag == 1:
    #  打印购物小条
    print("------------------购物小条---------------------")
    print("您的购物小条，请拿好：")
    t = time.strftime('%a %Y-%m-%d %H:%M:%S', time.localtime())
    print(t)
    print("商品种类 购买数量 花费")
    sum = 0
    for i in mycart:
        print(i)
        sum = sum + i[2]
    print("本次购物总共消费", sum, "元！")
    print("----------------------------------------------")
    print("您的本次余额还剩：￥",money,"!")












